﻿Namespace Facades

    Public NotInheritable Class AxisFacade

        Private brother As Infragistics.Windows.Chart.Axis

        Public Sub New(ByVal brother As Infragistics.Windows.Chart.Axis)
            MyBase.New()
            Me.brother = brother
        End Sub

        Public Property Maximum() As Double
            Get
                Return Me.brother.Maximum
            End Get
            Set(ByVal value As Double)
                Me.brother.Maximum = value
            End Set
        End Property

        Public Property Minimum() As Double
            Get
                Return Me.brother.Minimum
            End Get
            Set(ByVal value As Double)
                Me.brother.Minimum = value
            End Set
        End Property

        Public Property Unit() As Double
            Get
                Return Me.brother.Unit
            End Get
            Set(ByVal value As Double)
                Me.brother.Unit = value
            End Set
        End Property

        Public Property AutoRange() As Boolean
            Get
                Return Me.brother.AutoRange
            End Get
            Set(ByVal value As Boolean)
                Me.brother.AutoRange = value
            End Set
        End Property

        Public Property RangeFromZero() As Boolean
            Get
                Return Me.brother.RangeFromZero
            End Get
            Set(ByVal value As Boolean)
                Me.brother.RangeFromZero = value
            End Set
        End Property

        Public Property Crossing() As Double
            Get
                Return Me.brother.Crossing
            End Get
            Set(ByVal value As Double)
                Me.brother.Crossing = value
            End Set
        End Property

        Public Property Stroke() As System.Windows.Media.Brush
            Get
                Return Me.brother.Stroke
            End Get
            Set(ByVal value As System.Windows.Media.Brush)
                Me.brother.Stroke = value
            End Set
        End Property

        Public Property StrokeThickness() As Double
            Get
                Return Me.brother.StrokeThickness
            End Get
            Set(ByVal value As Double)
                Me.brother.StrokeThickness = value
            End Set
        End Property

        Public ReadOnly Property MinorGridline() As MarkFacade
            Get
                Return New MarkFacade(Me.brother.MinorGridline)

            End Get
        End Property

        Public ReadOnly Property MajorGridline() As MarkFacade
            Get
                Return New MarkFacade(Me.brother.MajorGridline)
            End Get
        End Property

        Public ReadOnly Property MajorTickMark() As MarkFacade
            Get
                Return New MarkFacade(Me.brother.MajorTickMark)
            End Get
        End Property

        Public ReadOnly Property MinorTickMark() As MarkFacade
            Get
                Return New MarkFacade(Me.brother.MinorTickMark)
            End Get
        End Property

        Public ReadOnly Property Label() As LabelFacade
            Get
                Return New LabelFacade(Me.brother.Label)
            End Get
        End Property

        Public Property Visible() As Boolean
            Get
                Return Me.brother.Visible
            End Get
            Set(ByVal value As Boolean)
                Me.brother.Visible = value
            End Set
        End Property

        'Public ReadOnly Property Stripes() As Infragistics.Windows.Chart.StripeCollection
        '    Get
        '        Return Me.brother.Stripes
        '    End Get
        'End Property

        ' Private _Animate0 As Boolean = True
        Public Property Animate As Boolean
            Get
                Return Not Me.brother.Animation Is Nothing
            End Get
            Set(ByVal value As Boolean)
                Me.brother.Animation = If(value, _animation, Nothing)
            End Set
        End Property

        Private _animation As Infragistics.Windows.Chart.Animation
        Public Property Animation As AnimationFacade
            Get
                If Me.brother.Animation IsNot Nothing Then Return New AnimationFacade(Me.brother.Animation)

                If _animation Is Nothing Then _animation = New Infragistics.Windows.Chart.Animation()

                If _animation IsNot Nothing Then Return New AnimationFacade(_animation)

                Return Nothing
            End Get
            Set(ByVal value As AnimationFacade)

            End Set
        End Property


        Public Function InternalToXElement() As XElement
         
            Dim x = <Axis
                        Maximum=<%= Maximum %>
                        Minimum=<%= Minimum %>
                        Unit=<%= Unit %>
                        AutoRange=<%= AutoRange %>
                        RangeFromZero=<%= RangeFromZero %>
                        Crossing=<%= Crossing %>
                        Stroke=<%= Stroke %>
                        StrokeThickness=<%= StrokeThickness %>
                        Visible=<%= Visible %>
                        Animate=<%= Animate %>
                        >


                    </Axis>

            x.Add(Label.InternalToXElement())
            x.Add(Animation.InternalToXElement())
            x.Add(MajorGridline.InternalToXElement())
            x.Add(MinorGridline.InternalToXElement())

            Return x
        End Function

        Public Sub InternalFromXElement(ByVal x As System.Xml.Linq.XElement)
            Dim cd = Function(s As String) Double.Parse(s, Globalization.CultureInfo.InvariantCulture)
            Dim cc = Function(s As String) If(String.IsNullOrEmpty(s), Nothing, (New Windows.Media.BrushConverter()).ConvertFromString(s))
            Dim ct = Function(s As String) (New Windows.ThicknessConverter()).ConvertFromInvariantString(s)

            Me.Maximum = cd(x.@Maximum)
            Me.Minimum = cd(x.@Minimum)
            Me.Unit = cd(x.@Unit)
            Me.AutoRange = x.@AutoRange
            Me.RangeFromZero = x.@RangeFromZero
            Me.Crossing = cd(x.@Crossing)
            Me.Stroke = cc(x.@Stroke)
            Me.StrokeThickness = cd(x.@StrokeThickness)
            Me.MinorGridline.InternalFromXElement(x.<Mark>.ElementAt(1))
            Me.MajorGridline.InternalFromXElement(x.<Mark>.ElementAt(0))
            'Me.MajorTickMark = x.@MajorTickMark
            'Me.MinorTickMark = x.@MinorTickMark
            Me.Label.InternalFromXElement(x.<Label>.First())
            Me.Visible = x.@Visible
            _animation = New Infragistics.Windows.Chart.Animation()
            Dim o = (New AnimationFacade(_animation))
            o.InternalFromXElement(x.<Animation>.First())
            Me.Animate = x.@Animate


        
        End Sub

        Public Sub Update(ByVal source As AxisFacade)
            Me.Maximum = source.Maximum
            Me.Minimum = source.Minimum
            Me.Unit = source.Unit
            Me.AutoRange = source.AutoRange
            Me.RangeFromZero = source.RangeFromZero
            Me.Crossing = source.Crossing
            Me.Stroke = source.Stroke
            Me.StrokeThickness = source.StrokeThickness

            Me.Visible = source.Visible
            _animation = New Infragistics.Windows.Chart.Animation()
            _animation.AccelerationRatio = source.Animation.AccelerationRatio
            _animation.DecelerationRatio = source.Animation.DecelerationRatio
            _animation.Duration = TimeSpan.FromSeconds(source.Animation.Duration)
            _animation.Sequential = source.Animation.Sequential
            Me.Animate = source.Animate
            'Me.MinorGridline.InternalFromXElement(x.<Mark>.ElementAt(1))
            'Me.MajorGridline.InternalFromXElement(x.<Mark>.ElementAt(0))
            ''Me.MajorTickMark = source.MajorTickMark
            ''Me.MinorTickMark = source.MinorTickMark
            'Me.Label.InternalFromXElement(x.<Label>.First())
        End Sub
    End Class
End Namespace
